<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>请做题</title>
    <!-- Bootstrap -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/bootstrap-table.css" rel="stylesheet"/>
    <link href="css/bootstrap-select.min.css" rel="stylesheet"/>
    <link href="css/bootstrap-markdown.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.9/css/all.css" integrity="sha384-5SOiIsAziJl6AWe0HWRKTXlfcSHKmYV4RBF18PPJ173Kzn7jzMyFuTtk8JA7QQG1" crossorigin="anonymous">
    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>



    </style>
</head>
<body>


<div class="container">
        <h2 class="form-signin-heading">请自测回答下列问题</h2>
        <br>
        <div id="ti"></div>

    <!-- 添加模态框（Modal） -->
    <div class="modal fade" id="myModa1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
        <div class="modal-dialog">
            <div class="modal-content">

                <div class="modal-body">
                    <input type="hidden" name="subjectId" id="sidtt1">
                    <textarea name="answerText" id="editor1" class='editor' style='color:#000' placeholder="请按回车换行之后输入代码"></textarea>
                </div>
                <div class="modal-footer" >
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="submitform1()">提交</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="myModa2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
        <div class="modal-dialog">
            <div class="modal-content">

                <div class="modal-body">
                    <input type="hidden" name="subjectId" id="sidtt2">
                    <textarea name="answerText" id="editor2" class='editor' style='color:#000' placeholder="请按回车换行之后输入代码"></textarea>
                </div>
                <div class="modal-footer" >
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="submitform2()">提交</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="myModa3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
        <div class="modal-dialog">
            <div class="modal-content">

                <div class="modal-body">
                    <input type="hidden" name="subjectId" id="sidtt3">
                    <textarea name="answerText" id="editor3" class='editor' style='color:#000' placeholder="请按回车换行之后输入代码"></textarea>
                </div>
                <div class="modal-footer" >
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="submitform3()">提交</button>
                </div>
            </div>
        </div>
    </div>

</div> <!-- /container -->

<!-- jQuery Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边 -->
<script src="js/jquery-3.3.1.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-table.js"></script>
<script src="js/bootstrap-table-zh-CN.js"></script>
<script src="js/bootstrap-select.min.js"></script>
<script src="js/bootstrap-markdown.js"></script>
<script src="locale/bootstrap-markdown.zh.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
    $("#md").on("keyup blur",function () {
        $('#html').html(marked($("#md").val()))
    })

    $(function() {
        //显示中文提示
        (function ($) {
            $.fn.markdown.messages.zh = {
                'Bold': "粗体",
                'Italic': "斜体",
                'Heading': "标题",
                'URL/Link': "链接",
                'Image': "图片",
                'List': "列表",
                'Unordered List': "无序列表",
                'Ordered List': "有序列表",
                'Code': "代码",
                'Quote': "引用",
                'Preview': "预览",
                'strong text': "粗体",
                'emphasized text': "强调",
                'heading text': "标题",
                'enter link description here': "输入链接说明",
                'Insert Hyperlink': "URL地址",
                'enter image description here': "输入图片说明",
                'Insert Image Hyperlink': "图片URL地址",
                'enter image title here': "在这里输入图片标题",
                'list text here': "这里是列表文本",
                'code text here': "这里输入代码",
                'quote here': "这里输入引用文本"
            };
        }(jQuery));


        var $editor = $(".editor");

        $editor.markdown({
            height:500,
            language:'zh',
            autofocus: true,
            iconlibrary:'fa',

        });

        $.ajax({
            url: '/rsm/subject/showSubject.do',
            async: true,
            type: "get",
            dataType:'json',
            success: function (data) {
//                console.info(data);
//                console.info(data.length)
                var html = "";
                for(var i=0;i<data.length;i++){

                    console.info(data[i].content)
                    var content = data[i].content;
                    var sbid1 = data[i].sbid;
                    var tmm = "<p>"+content+ "<span style='color: #b92c28' onclick='dati"+i+"("+sbid1+")'>【开始答题】</span></p>";
                    html += tmm;
                }

                $("#ti").html(html);
            }
        });

    });
    
    function dati0(sbid) {
        $("#sidtt1").val(sbid);
        $('#myModa1').modal();
    }
    function dati1(sbid) {
        $("#sidtt2").val(sbid);
        $('#myModa2').modal();
    }
    function dati2(sbid) {
        $("#sidtt3").val(sbid);
        $('#myModa3').modal();
    }

    function submitform1() {
//        $("#addForm").submit();editor
        var subjectId = $("#sidtt1").val();
        var answerText = $("#editor1").val();
        console.info(answerText);
        $.ajax({
            type : 'post',
            url : "/rsm/answer/submitAnswer.do",
            data: {subjectId:subjectId,answerText:answerText},
            dataType : 'json',
            success : function(datas) {
                //返回list数据并循环获取
                $('#myModa1').modal('hide');
            }
        });
    }
    function submitform2() {
//        $("#addForm").submit();editor
        var subjectId = $("#sidtt2").val();
        var answerText = $("#editor2").val();
        console.info(answerText);
        $.ajax({
            type : 'post',
            url : "/rsm/answer/submitAnswer.do",
            data: {subjectId:subjectId,answerText:answerText},
            dataType : 'json',
            success : function(datas) {
                //返回list数据并循环获取
                $('#myModa2').modal('hide');
            }
        });
    }
    function submitform3() {
//        $("#addForm").submit();editor
        var subjectId = $("#sidtt3").val();
        var answerText = $("#editor3").val();
        console.info(answerText);
        $.ajax({
            type : 'post',
            url : "/rsm/answer/submitAnswer.do",
            data: {subjectId:subjectId,answerText:answerText},
            dataType : 'json',
            success : function(datas) {
                //返回list数据并循环获取
                $('#myModa3').modal('hide');
            }
        });
    }


</script>
</body>
</html>
